/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: persist-jpa20
 * Description: Persistence implementation with JPA 2.0
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.persist.jpa20.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import ru.ffind.common.model.Host;
import ru.ffind.common.model.HostType;

/**
 * Host object implementation.
 *
 * FIXME Add group_id (or Group itself) implementation.
 *
 * @author Rage Steel
 */
@Entity(name = "Hosts")
@Table(name = "ff_hosts")
public class HostImpl implements Serializable, Host {

	private static final long serialVersionUID = -3184548232849578251L;

	private Integer id;

    private HostType type;

    private String name;

    private Integer ip;

    private Integer port;

    private String login;

    private String pass;

    private String owner;

    private Integer ownerUserId;

    private Integer ownerTopic;

    private String ownerUrl;

    private String description;

    private Date dateAdd;

    // FIXME Use hostOpt
    private Integer opt;

    // FIXME Use hostStatus
    private Integer status;

    private Integer lockPid;

    private Date lockDateTime;

    private DirImpl rootDir;

    // FIXME Use connErr object
    private Integer connErr;

    private Date connOk;

    private Date connLast;

    private Date crawlLast;

    private String resumePath;

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getId()
	 */
    @Override
	@Id
	@Column(name="host_id")
    public Integer getId() {
        return id;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setId(java.lang.Integer)
	 */
    @Override
	public void setId(Integer id) {
        this.id = id;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getType()
	 */
    @Override
    @Column(name = "host_type")
	public HostType getType() {
        return type;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setType(ru.ffind.common.model.HostType)
	 */
    @Override
	public void setType(HostType type) {
        this.type = type;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getName()
	 */
    @Override
    @Column(name = "host_name")
	public String getName() {
        return name;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setName(java.lang.String)
	 */
    @Override
	public void setName(String name) {
        this.name = name;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getIp()
	 */
    @Override
    @Column(name = "host_ip")
	public Integer getIp() {
        return ip;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setIp(java.lang.Integer)
	 */
    @Override
	public void setIp(Integer ip) {
        this.ip = ip;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getPort()
	 */
    @Override
    @Column(name = "host_port")
	public Integer getPort() {
        return port;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setPort(java.lang.Integer)
	 */
    @Override
	public void setPort(Integer port) {
        this.port = port;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getLogin()
	 */
    @Override
    @Column(name = "host_login")
	public String getLogin() {
        return login;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setLogin(java.lang.String)
	 */
    @Override
	public void setLogin(String login) {
        this.login = login;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getPass()
	 */
    @Override
    @Column(name = "host_pass")
	public String getPass() {
        return pass;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setPass(java.lang.String)
	 */
    @Override
	public void setPass(String pass) {
        this.pass = pass;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getOwner()
	 */
    @Override
    @Column(name = "host_owner")
	public String getOwner() {
        return owner;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setOwner(java.lang.String)
	 */
    @Override
	public void setOwner(String owner) {
        this.owner = owner;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getOwnerUserId()
	 */
    @Override
    @Column(name = "owner_user_id")
	public Integer getOwnerUserId() {
        return ownerUserId;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setOwnerUserId(java.lang.Integer)
	 */
    @Override
	public void setOwnerUserId(Integer ownerUserId) {
        this.ownerUserId = ownerUserId;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getOwnerTopic()
	 */
    @Override
    @Column(name = "owner_topic")
	public Integer getOwnerTopic() {
        return ownerTopic;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setOwnerTopic(java.lang.Integer)
	 */
    @Override
	public void setOwnerTopic(Integer ownerTopic) {
        this.ownerTopic = ownerTopic;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getOwnerUrl()
	 */
    @Override
    @Column(name = "owner_url")
	public String getOwnerUrl() {
        return ownerUrl;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setOwnerUrl(java.lang.String)
	 */
    @Override
	public void setOwnerUrl(String ownerUrl) {
        this.ownerUrl = ownerUrl;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getDescription()
	 */
    @Override
    @Column(name = "host_desc")
	public String getDescription() {
        return description;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setDescription(java.lang.String)
	 */
    @Override
	public void setDescription(String description) {
        this.description = description;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getDateAdd()
	 */
    @Override
    @Column(name = "date_add")
	@Temporal(TemporalType.DATE)
    public Date getDateAdd() {
        return dateAdd;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setDateAdd(java.util.Date)
	 */
    @Override
	public void setDateAdd(Date dateAdd) {
        this.dateAdd = dateAdd;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getOpt()
	 */
    @Override
    @Column(name = "host_opt")
	public Integer getOpt() {
        return opt;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setOpt(java.lang.Integer)
	 */
    @Override
	public void setOpt(Integer opt) {
        this.opt = opt;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getStatus()
	 */
    @Override
    @Column(name = "host_status")
	public Integer getStatus() {
        return status;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setStatus(java.lang.Integer)
	 */
    @Override
	public void setStatus(Integer status) {
        this.status = status;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getLockPid()
	 */
    @Override
    @Column(name = "lock_pid")
	public Integer getLockPid() {
        return lockPid;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setLockPid(java.lang.Integer)
	 */
    @Override
	public void setLockPid(Integer lockPid) {
        this.lockPid = lockPid;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getLockDateTime()
	 */
    @Override
    @Column(name = "lock_datetime")
	@Temporal(TemporalType.TIMESTAMP)
    public Date getLockDateTime() {
        return lockDateTime;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setLockDateTime(java.util.Date)
	 */
    @Override
	public void setLockDateTime(Date lockDateTime) {
        this.lockDateTime = lockDateTime;
    }

    @ManyToOne
    @JoinColumn(name = "root_dir_id")
    public DirImpl getRootDir() {
        return rootDir;
    }

    public void setRootDir(DirImpl rootDir) {
        this.rootDir = rootDir;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getRootDirId()
	 */
    @Override
    @Transient
    public Integer getRootDirId() {
        return (null == rootDir) ? rootDir.getId() : null;
    }

    @Override
    public void setRootDirId(Integer rootDirId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getConnErr()
	 */
    @Override
    @Column(name = "conn_error")
	public Integer getConnErr() {
        return connErr;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setConnErr(java.lang.Integer)
	 */
    @Override
	public void setConnErr(Integer connErr) {
        this.connErr = connErr;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getConnOk()
	 */
    @Override
    @Column(name = "conn_ok")
	@Temporal(TemporalType.TIMESTAMP)
    public Date getConnOk() {
        return connOk;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setConnOk(java.util.Date)
	 */
    @Override
	public void setConnOk(Date connOk) {
        this.connOk = connOk;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getConnLast()
	 */
    @Override
    @Column(name = "conn_last")
	@Temporal(TemporalType.TIMESTAMP)
    public Date getConnLast() {
        return connLast;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setConnLast(java.util.Date)
	 */
    @Override
	public void setConnLast(Date connLast) {
        this.connLast = connLast;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getCrawlLast()
	 */
    @Override
    @Column(name = "crawl_last")
	@Temporal(TemporalType.TIMESTAMP)
    public Date getCrawlLast() {
        return crawlLast;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setCrawlLast(java.util.Date)
	 */
    @Override
	public void setCrawlLast(Date crawlLast) {
        this.crawlLast = crawlLast;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#getResumePath()
	 */
    @Override
    @Column(name = "resume_path")
	public String getResumePath() {
        return resumePath;
    }

    /* (non-Javadoc)
	 * @see ru.ffind.persist.jpa20.model.Host#setResumePath(java.lang.String)
	 */
    @Override
	public void setResumePath(String resumePath) {
        this.resumePath = resumePath;
    }
}